<template>
	<div class="port-page">
		<!-- 顶部按钮 -->
		<el-tabs v-model="activeName" style="margin-top: 30px;" type="card" @tab-click='tabchk'>
			<el-tab-pane label="当前信息" name="dangqian"></el-tab-pane>
			<el-tab-pane label="总趋势" name="qushi"></el-tab-pane>
		</el-tabs>
		<div class="but1">
			<router-link to="/home">
				<el-button type="warning" size="small" class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
			</router-link>
			<el-date-picker v-if="sjshow" v-model="btime" type="date" style="line-height: 40px; width: 150px;"   placeholder="选择开始日期"  value-format="yyyy-MM-dd">
			</el-date-picker>
			<el-date-picker v-if="sjshow" v-model="etime" type="date" style="line-height: 40px; width: 150px;"   placeholder="选择结束日期"  value-format="yyyy-MM-dd">
			</el-date-picker>
			 <el-button  icon="el-icon-search" v-if="sjshow" type="primary" round size="small" style="margin-left: 20px;" @click="searchlist"></el-button>
		</div>
		<!-- 模糊搜索条件 -->
		<!--<div style="width: 100%;text-align: center;font-size: 30px;float: left;margin-top: 20%;color: red;">-->
		<div id="rstj" style="width: 100%;height: 400px;margin-top: 50px;"></div>
		<!--</div>-->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import echarts from 'echarts'
	import qs from 'qs'
	export default {
		props: ['params'],
		components: {
			LoadingComponent,
		},
		data() {
			return {
				sjshow:false,
				btime:'',
				etime:'',
				activeName: 'dangqian',
				bjrs: [],
				mbv: [],
				mc: [],
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/

				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/

			}
		},
		created() {
			//权限
			var logininfo = JSON.parse(localStorage.logininfo);
			//加载页面时调用
			this.$store.dispatch('changeTitle', '人数统计'); //修改title
			this.$store.dispatch('changeRouterIndex', '/statistics/persontj'); //修改路由
			 var nowDate = new Date();
			 var year = nowDate.getFullYear();
			 var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
			 var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
			 var dateStr = year + "-" + month + "-" + day;
			 var dateStr1 = year + "-" + month + "-" + '01';
			 this.btime = dateStr1
			 this.etime = dateStr
			 this.search('bjrs');
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			tabchk(tab) {
				if(tab.name == 'dangqian') {
					this.search('bjrs')
					this.sjshow=false
				} else if(tab.name == 'qushi') {
					this.sjshow=true
					this.search('xxrs')
					this.search('rqx')
				}

			},
			searchlist(){
				this.search('xxrs')
				this.search('rqx')
			},
			drawPie2(id, lststr) {
				this.charts = echarts.init(document.getElementById(id))
				var colors = ['#d14a61', '#675bba'];
				this.charts.setOption({
					title: {
						text: '人数统计',
					},
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'cross'
						}
					},
					legend: {
						data: ['人数', '满班率']
					},
					toolbox: {
						show: true,
						feature: {
							dataView: {
								show: true,
								readOnly: false
							},
							magicType: {
								show: true,
								type: ['line', 'bar']
							},
							restore: {
								show: true
							},
							saveAsImage: {
								show: true
							}
						}
					},
					xAxis: [{
						type: 'category',
						data: this.mc
					}],
					yAxis: [{
							type: 'value',
							name: '人数',
							//							min: 0,
							//							max: 250,
							position: 'left',
							axisLine: {
								lineStyle: {
									color: colors[0]
								}
							},
							axisLabel: {
								formatter: '{value}'
							}
						},
						{
							type: 'value',
							name: '满班率',
							min: 0,
							max: 100,
							position: 'right',
							axisLine: {
								lineStyle: {
									color: colors[1]
								}
							},
							axisLabel: {
								formatter: '{value} %'
							}
						}
					],
					series: [{
							name: '人数',
							type: 'bar',
							data: this.bjrs,

						},
						{
							name: '满班率',
							type: 'bar',
							yAxisIndex: 1,
							data: this.mbv,
						}
					]
				})
			},
			search(id) {
				this.bjrs = ''
				this.mbv = ''
				this.mc = ''
				//查询搜索触发事件
				var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
				var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params3 = qs.stringify({
					day: 1,
					code: id,
					lsid: '',
					bjtime: this.btime,
					edtime: this.etime,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.axios.post(this.$store.state.api + 'ls/getlstj', params3)
					.then(res => {
						console.log(res, 999988887777)
						if(id == 'bjrs') {
							var list = res.data.data
							var mc = list.mc.substr(0, list.mc.length - 1)
							this.bjrs = res.data.data.bjrs.split(",");
							this.mbv = res.data.data.mbv.split(",");
							this.mc = mc.split(",");
						} else {
							if(id == 'xxrs') {
								var list = res.data.data
								var mc = list.sj.substr(0, list.sj.length - 1)
								this.mc = mc.split(",");
								this.bjrs = res.data.data.cqv.split(",");
							} else if(id == 'rqx') {
								var list = res.data.data
								var mc = list.sj.substr(0, list.sj.length - 1)
								this.mc = mc.split(",");
								this.mbv = res.data.data.mbv.split(",");
							}
						}

						this.$nextTick(function() {
							this.drawPie2('rstj')
						});
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},

			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				// console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
.el-input__prefix {
    height: 100%;
    
}
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 100px;
			max-width: 135px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
			margin-right: 10px;
		}
		.but1 {
			width: 100%;
			float: left;
		}
		.search {
			width: 77%;
			float: right;
			text-align: right;
		}
		.el-button+.el-button {
			margin-left: 0px;
			margin-top: 8px;
		}
	}
</style>